<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>Title</title>
    <script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
</head>
<body>
<form action="/lg/login" method="post">
    <input type="text" id="username" name="username" />
    <input type="text" id="password" name="password" />
    <input type="button" onclick="f1()" value="登录"/>
</form>
<input type="text" id="test1" name="id" value=""/>
<input type="button" id="test2" onclick="f3()" value="test"/>

</body>
<script type="text/javascript">
    function f1() {
        var a = $('#test1').val();
        alert(a == null);
    }
    
    function f2() {
        var jsonObject = [];
        var inputs = $("input");
        var j = 0;
        var i;

        for(i = 0; i < inputs.length; i++) {
            alert(inputs.length);
            var input = inputs[i];
            var key = input.attr('name');
            var value = input.val();
            if(value != "") {
                var tempObject = new Object();
                tempObject.id = key;
                tempObject.configValue = value;
                jsonObject[j++] = tempObject;
            }
        }
        alert(JSON.stringify(jsonObject));
    }

    function f3() {
        var jsonObject = [];
        var inputs = $("input");
        var j = 0;
        inputs.each(function () {
            //alert($(this).attr('name'));
            var key = $(this).attr('name');
            var value = $(this).val();
            if(value != "") {
                var tempObject = new Object();
                tempObject.id = key;
                tempObject.configValue = value;
                jsonObject[j++] = tempObject;
            }
        });
        alert(JSON.stringify(jsonObject));

    }


</script>
</html>